package com.oig.sys.log.util;

import cn.hutool.core.util.URLUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.http.HttpUtil;
import com.oig.common.util.RequestHeaderUtil;
import com.oig.common.util.SpringContextUtil;
import com.oig.sys.log.dto.SysLogDto;
import lombok.experimental.UtilityClass;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@UtilityClass
public class SysLogUtils {

    public SysLogDto buildSysLog(){
        SysLogDto logDto = new SysLogDto();
        HttpServletRequest request = SpringContextUtil.getRequest() ;
        logDto.setSystemId(RequestHeaderUtil.getSystemId());   //系统      --可以在add的地方通过api去查
        logDto.setResourceId(RequestHeaderUtil.getResourceId()); //模块
//        logDto.setOptObjId();   //数据id     --无法获取了
//        logDto.setContent();    //操作内容   --无效了
        if (request!=null){
            logDto.setApiUrl(URLUtil.getPath(request.getRequestURI()));
            logDto.setOldval(HttpUtil.toParams(request.getParameterMap()));     //数据参数
            logDto.setLoginIp(ServletUtil.getClientIP(request));
        }
        logDto.setOptTime(new Date());

        return logDto;

    }

}
